package org.liang.utils;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class SendEmail {

    public static void sendQQEmail(String emailFrom,String emailTo,String text,JavaMailSender javaMailSender){
        //发送邮件
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = null;
        try {
            helper = new MimeMessageHelper(mimeMessage, true, "utf-8");
            System.out.println("emailName:"+emailFrom);
            //设置发送人
            helper.setFrom(emailFrom);
            //收件人
            helper.setTo(emailTo);
            //邮件主题
            helper.setSubject("蓉礼购");
            //邮件内容
            helper.setText(text,true);
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

}
